// components/goods_card/index.js
Component({
  options: {
    addGlobalClass: true,
  },
  properties: {
    data:{
      type:Object,
      value:{price:0,delPrice:0}
    },
    selected: {
      type:Boolean,
      value:true,
      observer(newVal, oldVal, path){
        this.setData({selectedData:newVal});
      }
    },
  },
  data: {
    selectedData: true,
    numBuysData:0
  },
  lifetimes: {
    attached() {
      this.setData({selectedData:this.properties.data.selected});
      this.setData({numBuysData:this.properties.data.numBuys});
    }
  },
  methods: {
    onCBChange() {
      this.setData({selectedData:!this.data.selectedData});
      this.triggerEvent('change_cb',{id:this.properties.data.id,selected:this.data.selectedData});
    },
    onDelete(e) {
      console.log('onDelete:',this.properties.data.id);
      this.triggerEvent('delete',{id:this.properties.data.id});
    },
    onStepperChange(e) {
      //console.log('onStepperChange:',e.detail.count);
      this.triggerEvent('step',{id:this.properties.data.id,count:e.detail.count});
      this.setData({numBuysData:e.detail.count});
    },
    setCount(count) {
      this.selectComponent('#stepper').setCount(count);
    },
    getCount() {
      return this.selectComponent('#stepper').getCount();
    },
    toDetail(e) {
      wx.navigateTo({url: '/pages/goods/detail/index?id='+this.properties.data.id});
    }
  }
})
